//
//  DRUpgradingView.m
//  bse
//
//  Created by 3iRobot2020 on 2021/6/5.
//

#import "DRUpgradingView.h"
#import "DRCircleView.h"

#define MarginRate 0.2
@interface DRUpgradingView()
@property (nonatomic,strong)DRCircleView *progressView;//动画视图
@property (nonatomic, strong) UILabel *progressLabel;//进度文字
@property (nonatomic,strong)UIView *progressUnderView;//动画背景视图

@end

@implementation DRUpgradingView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        
    }
    return self;
}

-(void)setModel:(DRUpgradingModel *)model{
    self.layer.cornerRadius = model.contentRadius;
    self.layer.masksToBounds = YES;
    CGFloat width = model.contentWidth;
    CGFloat height = model.contentHeight;
    CGFloat circleWidth = width;
    CGFloat circleX = 0;
    CGFloat circleY = 0;
    if (width >= height) { //宽 > 高
        circleWidth = height *(1 - MarginRate * 2) ;
    }else{//宽 < 高
        circleWidth = width *(1 - MarginRate * 2) ;
    }
    circleX = 0.5 * (width - circleWidth);
    circleY = 0.5 * (height - circleWidth);
    self.progressUnderView.frame = CGRectMake(circleX, circleY, circleWidth, circleWidth);
    self.progressUnderView.layer.cornerRadius = 0.5 * circleWidth;
    self.progressUnderView.layer.borderColor = model.prgressUnDoColor.CGColor;
    self.progressUnderView.layer.borderWidth = model.lineWidth;
    self.progressUnderView.layer.masksToBounds = YES;
    
    self.progressView.frame = CGRectMake(circleX, circleY, circleWidth, circleWidth);
    self.progressView.progressColor = model.prgressDoColor;
    self.progressView.lineWidth = model.lineWidth;
}

-(void)setProgress:(CGFloat)progress{
    _progress = progress;
    self.progressView.progress = progress;
}

-(UIView *)progressUnderView{
    if (!_progressUnderView) {
        _progressUnderView = [[UIView alloc] init];
//        _progressUnderView.backgroundColor = [UIColor clearColor];
        [self addSubview:_progressUnderView];
    }
    return _progressUnderView;
}

-(DRCircleView *)progressView{
    if (!_progressView) {
        _progressView = [[DRCircleView alloc] init];
//        _progressView.backgroundColor = [UIColor clearColor];
        [self addSubview:_progressView];
    }
    return _progressView;
}


-(UILabel *)progressLabel{
    if (!_progressLabel) {
        _progressLabel = [[UILabel alloc] init];
        _progressLabel.backgroundColor = [UIColor clearColor];
    }
    return _progressLabel;
}


@end
